﻿#region References
using System;
using System.Text;
using System.Collections.Generic;

using Xen;
using Xen.Camera;
using Xen.Graphics;
using Xen.Ex.Graphics;
using Xen.Ex.Graphics2D;
using Xen.Ex.Material;
using Xen.Graphics.State;
using Xen.Ex.Graphics.Content;
using Xen.Ex.Geometry;
using Xen.Ex;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
#endregion

namespace Ness.Engine.Graphics
{
    /// <summary>
    /// Base class for ANY drawable object
    /// </summary>
    class DebugDrawer : IDraw, IContentOwner
    {

        #region Public variables
        public Matrix worldMatrix;
        public Engine game;
        #endregion

        /// <summary>
        /// Initialises the Actor
        /// </summary>
        /// <param name="game">The engine instance currently in use</param>
        /// <param name="model">The path of the model, relative to Content</param>
        public DebugDrawer(Engine game)
        {
            //Set needed variables
            this.game = game;

            //Add the actor to the content register
            game.Content.Add(this);
        }

        /// <summary>
        /// Moves the model to a Vector3 position
        /// </summary>
        /// <param name="position">The 3D Vector in which to move the model to</param>
        public void MoveTo(Vector3 position)
        {
            Matrix.CreateTranslation(ref position, out this.worldMatrix);
        }

        /// <summary>
        /// Draws the debug assets
        /// </summary>
        /// <param name="state">Passed automatically. Ignore.</param>
        public void Draw(DrawState state)
        {
            //Get a simple shader from Xen.Ex that fills a solid colour
            Xen.Ex.Shaders.FillSolidColour shader = state.GetShader<Xen.Ex.Shaders.FillSolidColour>();

            shader.FillColour = new Vector4(255, 0, 255, 50);

            shader.Bind(state);

            //push the render state...
            state.PushRenderState();

            state.RenderState.DepthColourCull.CullMode = CullMode.None;
            state.RenderState.DepthColourCull.FillMode = FillMode.WireFrame;

            //Draw triggers
            foreach (Ness.Engine.Interact.EventTrigger trigger in game.eventTriggers)
            {
                (new Xen.Ex.Geometry.Cube(trigger.minimum, trigger.maximum)).Draw(state);
            }

            state.PopRenderState();
        }

        public void LoadContent(ContentRegister content, DrawState state, ContentManager manager)
        {
        }

        public void UnloadContent(ContentRegister content, DrawState state)
        {
        }

        public bool CullTest(ICuller cull)
        {
            return true;
        }


    }
}
